home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -serious- / programming / other / tandem / teaching / 45.asm < prev    next >
Assembly Source File  |  1999-09-06  |  3KB  |  100 lines

  1. * 45.asm    TLfloat              version 0.01    8.6.99
  2.  
  3.  
  4.  include 'Front.i'         ;*** change to 'Tandem.i' to step thru TL's ***
  5.  
  6.  
  7. ; TLfloat allows you to change an ASCII string to the format that an FPU
  8. ; uses for its input. Strangely, tandem.library does not use the FPU to
  9. ; do TLfloat, but of course the FPU would immediately be called to FMOVE
  10. ; TLfloat's output into one of its registers.
  11.  
  12. ; TLfloat points A0 to the delimiter of the float, so for example if you
  13. ; input  123.45,  then TLfloat will return with A0 pointint to the , which
  14. ; is the delimiter of the float. Thus, you can use TLfloat to evaluate
  15. ; 1 by 1 sets of floats separated by commas, spaces, or whatever. TLfloat
  16. ; is very flexible and hopefully clever in what it will accept as an input.
  17.  
  18.  
  19. strings: dc.b 0
  20. st_1: dc.b 'Test TLFloat',0 ;1
  21.  dc.b 'Input a float (e.g. -123.45, 1.76E-5)',0 ;2
  22.  dc.b 'bad: no mantissa digits ',0 ;3
  23.  dc.b 'bad: abs(exponent)>999 after normalising ',0 ;4
  24.  dc.b 'bad: no digits after E ',0 ;5
  25.  
  26.  ds.w 0
  27.  
  28.  
  29. * demonstrate TLfloat
  30. Program:
  31.  TLwindow #-1              ;initialise
  32.  beq Pr_quit
  33.  
  34. Pr_cyc:
  35.  clr.b (a4)
  36.  TLreqinput #2,str,#25     ;get next input
  37.  beq Pr_quit               ;done if cancel
  38.  
  39.  move.l a4,a0              ;tfr input to buff+100
  40.  move.l a4,a1
  41.  move.l a1,a2
  42.  add.l #100,a2             ;a2=buff+100
  43.  move.l a2,a1
  44. Pr_tfr:
  45.  move.b (a0)+,(a1)+
  46.  bne Pr_tfr
  47.  
  48.  move.l a4,a3              ;a3=buff+200
  49.  add.l #200,a3
  50.  
  51.  TLfloat a2,a3             ;put float in buff+200 (12 bytes)
  52.  bne.s Pr_good             ;go if good
  53.  
  54.  addq.w #2,d0              ;convert d0 to error string num
  55.  TLstra0 d0                ;point to error string
  56.  move.l a4,a1
  57. Pr_bad:
  58.  move.b (a0)+,(a1)+        ;error string to buffer
  59.  bne Pr_bad
  60.  bra.s Pr_pik              ;append for input
  61.  
  62. Pr_good:
  63.  move.l a3,a0              ;convert ouput to ASCII
  64.  move.l a4,a1
  65.  moveq #5,d1               ;(6 words)
  66.  
  67. Pr_word:
  68.  move.w (a0)+,d0           ;get word
  69.  moveq #3,d2               ;(4 nybbles)
  70.  
  71. Pr_nybb:
  72.  rol.w #4,d0               ;get next nybble
  73.  move.w d0,d3              ;convert to hex
  74.  and.w #15,d3
  75.  add.b #'0',d3
  76.  cmp.b #':',d3
  77.  bcs.s Pr_asc
  78.  add.b #'A'-':',d3         ;(only 1st byte should get here!)
  79.  
  80. Pr_asc:
  81.  move.b d3,(a1)+           ;put ASCII of nybble
  82.  dbra d2,Pr_nybb
  83.  move.b #' ',(a1)+         ;spc between words
  84.  dbra d1,Pr_word
  85.  
  86. Pr_pik:
  87.  move.b #'}',(a1)+         ;append '}' then input
  88.  move.b #' ',(a1)+
  89.  move.l a2,a0
  90.  
  91. Pr_app:
  92.  move.b (a0)+,(a1)+
  93.  bne Pr_app
  94.  
  95.  TLreqchoose               ;show 'output } input', wait for acknowledge
  96.  bra Pr_cyc                ;repeat until cancel
  97.  
  98. Pr_quit:
  99.  rts
  100.